package com.cyl.manager.oms.controller;

import com.cyl.manager.oms.domain.form.ManagerOrderInfoQueryForm;
import com.cyl.manager.oms.domain.form.ManagerPlaceOrderDTO;
import com.cyl.manager.oms.domain.vo.ManagerPlaceOrderVO;
import com.cyl.manager.oms.service.OrderInfoService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.enums.BusinessType;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;


/**
 * 下订单Controller
 *
 * @author zcc
 * @date 2022-12-01
 */
@Api(description = "下订单管理")
@RestController
@RequestMapping("/oms/orderInfo")
@Slf4j
public class OrderInfoController extends BaseController {
    @Autowired
    private OrderInfoService service;

    @ApiOperation("查询订单表列表")
    @PreAuthorize("@ss.hasPermi('oms:orderInfo:list')")
    @PostMapping("/list")
    public ResponseEntity<Page<ManagerPlaceOrderVO>> list(@RequestBody ManagerOrderInfoQueryForm query, Pageable page) {
        return ResponseEntity.ok(service.selectList(query, page));
    }


//    @ApiOperation("修改收件人信息")
//    @PostMapping("/receiver/update")
//    public ResponseEntity<Boolean> updateReceiver(@RequestBody Order order) {
//        return ResponseEntity.ok(service.updateReceiver(order));
//    }
//
//    @ApiOperation("导出订单表列表")
//    @PreAuthorize("@ss.hasPermi('oms:order:export')")
//    @Log(title = "订单表", businessType = BusinessType.EXPORT)
//    @GetMapping("/export")
//    public ResponseEntity<String> export(OrderQuery query) {

    /// /        List<Order> list = service.selectList(query, null);
    /// /        ExcelUtil<OrderVO> util = new ExcelUtil<>(OrderVO.class);
    /// /        return ResponseEntity.ok(util.writeExcel(convert.dos2vos(list), "订单表数据"));
//        return null;
//    }
//
//    @ApiOperation("获取订单表详细信息")
//    @PreAuthorize("@ss.hasPermi('oms:order:query')")
//    @GetMapping(value = "/{id}")
//    public ResponseEntity<ManagerOrderDetailVO> getInfo(@PathVariable("id") Long id) {
//        return ResponseEntity.ok(service.selectById(id));
//    }
//
//    @ApiOperation("新增订单表")
//    @PreAuthorize("@ss.hasPermi('oms:order:add')")
//    @Log(title = "订单表", businessType = BusinessType.INSERT)
//    @PostMapping
//    public ResponseEntity<Integer> add(@RequestBody Order order) {
//        return ResponseEntity.ok(service.insert(order));
//    }
//
//    @ApiOperation("修改订单表")
//    @PreAuthorize("@ss.hasPermi('oms:order:edit')")
//    @Log(title = "订单表", businessType = BusinessType.UPDATE)
//    @PutMapping
//    public ResponseEntity<Integer> edit(@RequestBody Order order) {
//        return ResponseEntity.ok(service.update(order));
//    }
    @ApiOperation("客服已处理")
    @PreAuthorize("@ss.hasPermi('oms:orderInfo:handle')")
    @Log(title = "下单-客服已处理", businessType = BusinessType.UPDATE)
    @PostMapping("/handle/{id}")
    public ResponseEntity<Boolean> handle(@PathVariable Long id) {
        return ResponseEntity.ok(service.handle(id));
    }

    @ApiOperation("已发货")
    @PreAuthorize("@ss.hasPermi('oms:orderInfo:send')")
    @Log(title = "下单-已发货", businessType = BusinessType.UPDATE)
    @PostMapping("/send/{id}")
    public ResponseEntity<Boolean> send(@PathVariable Long id) {
        return ResponseEntity.ok(service.send(id));
    }

    @ApiOperation("已收款")
    @PreAuthorize("@ss.hasPermi('oms:orderInfo:payment')")
    @Log(title = "下单-已收款", businessType = BusinessType.UPDATE)
    @PostMapping("/payment/{id}")
    public ResponseEntity<Boolean> payment(@PathVariable Long id) {
        return ResponseEntity.ok(service.payment(id));
    }

    @ApiOperation("修改")
    @PreAuthorize("@ss.hasPermi('oms:orderInfo:updata')")
    @Log(title = "下单-修改", businessType = BusinessType.UPDATE)
    @PostMapping("/updata")
    public ResponseEntity<Boolean> updata(@RequestBody @Valid ManagerPlaceOrderDTO managerPlaceOrder) {
        return ResponseEntity.ok(service.updata(managerPlaceOrder));
    }

}
